/**
 * 
 */
package com.jeecms.wicool.dao.user.impl;

import org.apache.commons.lang.StringUtils;

import com.jeecms.common.hibernate3.Finder;
import com.jeecms.common.hibernate3.HibernateBaseDao;
import com.jeecms.common.page.Pagination;
import com.jeecms.wicool.dao.user.CheckCodeDao;
import com.jeecms.wicool.entity.user.CheckCode;

/**
 * @author spring
 *
 */
public class CheckCodeDaoImpl extends HibernateBaseDao<CheckCode, Integer> implements CheckCodeDao {

	@Override
	public Pagination getPage(String school, String classes, String checkcode,
			int pageNo, int pageSize) {
		Finder f = Finder.create("select bean from CheckCode bean where 1=1 ");
		if(StringUtils.isNotEmpty(school)){
			f.append(" and bean.school = :school");
			f.setParam("school",school);
		}
		if(StringUtils.isNotEmpty(classes)){
			f.append(" and bean.classes = :classes");
			f.setParam("classes",classes);
		}
		if(StringUtils.isNotEmpty(checkcode)){
			f.append(" and bean.checkCode = :checkcode");
			f.setParam("checkcode",checkcode);
		}
		f.append(" order by bean.id desc");
		return find(f, pageNo, pageSize);
	}

	@Override
	public CheckCode findById(Integer id) {
		return get(id);
	}
	
	@Override
	public CheckCode save(CheckCode bean) {
		getSession().save(bean);
		return bean;
	}

	@Override
	public CheckCode deleteById(Integer id) {
		CheckCode bean = get(id);
		if(bean != null){
			getSession().delete(bean);
		}
		return bean;
	}

	@Override
	protected Class<CheckCode> getEntityClass() {
		return CheckCode.class;
	}

}
